# coding=utf-8
"""
author: jamon
"""

from enum import IntEnum, unique
from typing import Optional

_need_reload = True


@unique
class ActType(IntEnum):
    """操作类型"""
    MOVE = 1   # 移动
    SHOOT = 2  # 开火
    STOP = 3   # 停止


class ActRecord(object):
    """操作记录"""
    def __init__(self, act_type: ActType, user_id: int,
                 frame_no: Optional[int] = None, **kwargs):
        self.act_type: ActType = act_type
        self.user_id: int = user_id
        self.frame_no: Optional[int] = frame_no   # 逻辑帧
        self.extra_params: dict = kwargs

    def set_frame_no(self, new_frame_no: int):
        self.frame_no = new_frame_no

    def to_dict(self):
        return {
            "act_type": self.act_type,
            "user_id": self.user_id,
            "frame_no": self.frame_no,
            "extra_params": self.extra_params
        }

    @classmethod
    def from_dict(cls, data: dict):
        obj = cls(**data)
        obj.extra_params = data.get("extra_params", {})
        return obj
